# _*_coding:utf-8_*_

TEST_TASK = 0
UAP_TASK = 1
LOT_LEVEL = 10
WAFER_LEVEL = 11
SITE_LEVEL = 12
SUBSITE_LEVEL = 13
DEV_LEVEL = 14
TEST_LEVEL = 15
PRB_TASK = 2
LOOP_TASK = 3
PARALLEL_TASK = 4


class BasicTask:
    def __init__(self, task_type):
        self.type = task_type

    def output(self):
        pass


class TestTask(BasicTask):
    def __init__(self, pyfile, locationInd, dli=None):
        BasicTask.__init__(self, TEST_TASK)
        self.pyfile = pyfile
        self.locationInd = locationInd
        self.dbLocId = dli
        self.loopId = None

    def output(self):
        print("TEST_TASK-->", self.locationInd, '>', self.pyfile)

    def get_location_ind(self):
        return self.locationInd


class UAPTask(BasicTask):
    def __init__(self, pyfile, uap_level):
        BasicTask.__init__(self, UAP_TASK)
        self.pyfile = pyfile
        self.uap_level = uap_level

    def output(self):
        print("UAP_TASK-->", self.pyfile)


# Specified task defined for semiconductor field 2013/03/26
class PrbTask(BasicTask):
    def __init__(self, Prb_opt, *args):
        BasicTask.__init__(self, PRB_TASK)
        self.prb_opt = Prb_opt
        self.args = args

    def output(self):
        print("PRB_TASK-->", self.prb_opt, self.args)


class Parallel_Task(BasicTask):
    def __init__(self, list4devtasks, devs):
        """
        list4devtasks:[[t1,t2],[t3,t4]]
        """
        BasicTask.__init__(self, PARALLEL_TASK)
        self.list4devtasks = list4devtasks
        self.devs = devs

    def output(self):
        print('#################parallel task output####################')
        i = -1
        for tasks in self.list4devtasks:
            i += 1
            print('*************begin %s task***************' % self.devs[i])
            for t in tasks:
                t.output()
            print('*************end of %s task**************' % self.devs[i])
        print('#########3##End of parallel task output##################')


class Loop_Task(BasicTask):
    def __init__(self, loopUnit, loopTasks, loopNum):
        """
        loopTasks:[Task Object]
        loopNum: repeat times. if loopNum=-1, it means to infinite run
        ssiteOrDevOrT: repeat item, subsite or device or test
        """
        BasicTask.__init__(self, LOOP_TASK)
        self.loopTasks = loopTasks
        self.loopNum = loopNum
        self.loopUnit = loopUnit

    def output(self):
        print('#################Repeat_Task output#######################%s' % self.loopUnit)
        print("Loop below %s for %s times" % (self.loopUnit, self.loopNum))
        for t in self.loopTasks:
            t.output()
        print('#################End Repeat_Task output#####################%s' % self.loopUnit)
